﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class city_s_forum : System.Web.UI.Page
{
    int no;

    protected void Page_Load(object sender, EventArgs e)
    {
        no = int.Parse(Request["no"]);

        if (!this.IsPostBack)
        {
            ctpDataContext db = new ctpDataContext();
            ct_s_profile cts = db.ct_s_profiles.Single(p => p.valid == true && p.no == no && p.language_no == (int)Session["now_user_lang_no"]);

            this.HyperLink3.Text = cts.title;
            this.HyperLink3.NavigateUrl = "city_s.aspx?no=" + no.ToString().Trim();
            this.HyperLink2.Text = cts.ct_profile.title.Trim();
            this.HyperLink2.NavigateUrl = "city.aspx?no=" + cts.ct_no;

            this.HyperLink9.NavigateUrl = "city_s_forum_new.aspx?no=" + no.ToString();
			
            var data = from p in db.ct_s_forums
                       where p.ct_s_no == no && p.reply_to==0
                       orderby p.last_post descending
                       select p;
            //init helper class
            GeoLingManager glManager = new GeoLingManager(Request, Response);
            String _lang = glManager.getLang();
            DatabaseUtil dbUtil = new DatabaseUtil();
            //Get user's preferred langugage in int
            _lang = dbUtil.getLanguageNo(_lang).ToString();
            ArrayList al = new ArrayList();
            foreach (ct_s_forum f in data)
            {
                f.user.profile_picture = f.user.profile_picture.Trim();
                al.Add(f.no);
            }
            //Get all translated text
            Hashtable titlesTable = dbUtil.getTranlatePosts((int)DatabaseUtil.fromTables.forum_title, DataUtil.ObjsToInts(al.ToArray()));
            Hashtable textsTable = dbUtil.getTranlatePosts((int)DatabaseUtil.fromTables.forum_text, DataUtil.ObjsToInts(al.ToArray()));
            foreach (ct_s_forum f in data)
            {
                f.text = dbUtil.getPropertyPost(f.text, textsTable, f.no, _lang);
                f.title = dbUtil.getPropertyPost(f.title, titlesTable, f.no, _lang);
            }
            this.GridView1.DataSource = data;
            this.DataBind();

        }


    }
}
